package com.conduit.comnands;

import java.awt.Robot;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

import org.sikuli.script.AppearEvent;
import org.sikuli.script.ChangeEvent;
import org.sikuli.script.Region;
import org.sikuli.script.Screen;
import org.sikuli.script.SikuliEventObserver;
import org.sikuli.script.SikuliScript;
import org.sikuli.script.VanishEvent;

import com.conduit.agent.Main;
import com.conduit.commands.prototype.AbstractCommand;
import com.conduit.enums.ResultCode;

public class TakeScreenShotCommand extends AbstractCommand {
	private Screen s;

	public TakeScreenShotCommand() {
		commandSyntax = "take a screenshot";

	}

	@Override
	public void executeWithArgs(String args) {
		try {
			int i = 1;
			s = new Screen();
			final Robot robot = new Robot();
			BufferedImage image = robot.createScreenCapture(s.getRect());
			ImageIO.write(image, "png", new File("screenshot" + i + ".png"));
			i++;
			System.out.println(String.format("%s, %s, %s, %s",
					Main.getMachineIp(), "A Screenshoot was Taken by The User", "screenshot"
							+ i + ".png", ResultCode.Successes.getResult()));

		} catch (Exception e) {
			
		}
	}

	public static void main(String[] args) {
		new TakeScreenShotCommand().executeWithArgs("");
	}

	@Override
	public String getCommandName() {
		// TODO Auto-generated method stub
		return "Take Screenshot Command";
	}

	public Screen getS() {
		return s;
	}

	public void setS(Screen s) {
		this.s = s;
	}

}
